﻿<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
     xmlns:b="clr-namespace:BusyReports;assembly=BusyReports"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:BusyReports="clr-namespace:BusyReports;assembly=BusyReports" mc:Ignorable="d" x:Class="BusyReportsGui.MainWindow"
        Title="BusyReportsGui" Height="751.775" Width="1038" Loaded="Window_Loaded" Closing="Window_Closing" Icon="icon.ico" Background="LightGray">
    <Window.Resources>

        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

        <BusyReports:BusyReportsViewModel x:Key="viewModel" />

    </Window.Resources>
    <Grid DataContext="{Binding Source={StaticResource viewModel}}">
        <StackPanel  >

            <DockPanel >

                <TextBox Text="{Binding Path=Filter}" Name="txtFilter" TextChanged="txtFilter_TextChanged"  Margin="5" GotFocus="txtFilter_GotFocus" Width="200" />

                <TextBox Text="{Binding Path=ConnectionInfo}" Name="txtDatabase" IsReadOnly="True" Margin="5" HorizontalAlignment="Right" Width="433"/>

            </DockPanel>
            <StackPanel > <!--="{StaticResource busySubscriptionViewSource}" -->
                <Grid>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="150"></ColumnDefinition>

                    </Grid.ColumnDefinitions>
                    <!-- ItemsSource="{Binding}"  -->
                    <DataGrid Height="200"
                    CanUserAddRows="False"
                    CanUserDeleteRows="False"
                    x:Name="busySubscriptionDataGrid" 
                    AutoGenerateColumns="False"
                    EnableRowVirtualization="True" 
                    ItemsSource="{Binding Path=Subscriptions, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                    SelectedItem="{Binding BusySubscription, UpdateSourceTrigger=PropertyChanged}"
                    Margin="5,5,5,5"
                    RowDetailsVisibilityMode="VisibleWhenSelected"
                     Grid.Column="0" >
                        <DataGrid.Columns>
                            <DataGridTextColumn x:Name="idColumn" Binding="{Binding id}" Header="id" Width="SizeToHeader" IsReadOnly="True"/>
                            <DataGridTextColumn x:Name="reportPathColumn" Binding="{Binding ReportPath}" Header="Report Path" Width="300" IsReadOnly="{Binding IsReadOnly,  Source={StaticResource viewModel}}">
                               
                            </DataGridTextColumn>
                            <DataGridTextColumn x:Name="typeColumn" Binding="{Binding Type}" Header="Type" Width="50" IsReadOnly="True" />
                            <DataGridTextColumn x:Name="lastRunColumn" Header="Last Run" Width="120" Binding="{Binding LastRun, StringFormat=yyyy/MM/dd hh:mm}" IsReadOnly="True" />
                            <DataGridTextColumn x:Name="lastRunDurationSecondsColumn" Binding="{Binding LastRunDurationSeconds}" Header="Last Run Duration(s)" Width="SizeToHeader" IsReadOnly="True"/>
                           
                            <DataGridTextColumn x:Name="lastStatusColumn" Binding="{Binding LastStatus}" Header="Last Status" Width="150" IsReadOnly="True"/>

                            <DataGridTemplateColumn Header="Show Log" Width="SizeToHeader" IsReadOnly="True">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock>
        <Hyperlink Click="showLog_Click">Show Log</Hyperlink>
                                        </TextBlock>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            
                        </DataGrid.Columns>
                    </DataGrid>
                    <StackPanel Grid.Column="1">
                        <Button Content="New Mail Subscription.." Margin="5,5,5,5" Click="btnNewMailSubscription_Click"  />
                        <Button Content="New File Subscription.." Margin="5,5,5,5" Click="btnNewFileSubscription_Click"  />
                        <Button Content="Delete" Margin="5,5,5,5" Click="btnDelete_Click"  />
                        <Button Content="Run" Margin="5,5,5,5" Click="btnRun_Click"  />
                        <Button Content="Test Run" Margin="5,5,5,5" Click="btnTestRun_Click"  />
                        
                    </StackPanel>
                </Grid>
            </StackPanel>
            <Grid Height="Auto"  >
                <Grid.ColumnDefinitions>

                    <ColumnDefinition Width="1*"></ColumnDefinition>
                    <ColumnDefinition Width="1*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <GridSplitter Grid.Column="1" 
              Grid.RowSpan="1" 
              HorizontalAlignment="Left" 
              VerticalAlignment="Stretch"
              Background="Black" 
              ShowsPreview="true"
              Width="3"></GridSplitter>
                <StackPanel Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" >
                    <Grid x:Name="gridReportPath" HorizontalAlignment="Stretch"
                           Margin="5,5,5,5" VerticalAlignment="Top" 
                           IsEnabled="{Binding IsEdit}"
                         >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="1*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                           
                        </Grid.RowDefinitions>
                        

                        <Label Content="ReportPath:" 
                                   Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="1" VerticalAlignment="Center"/>
                        <TextBox  Grid.Column="1" HorizontalAlignment="Stretch" Height="23" Margin="3" Grid.Row="1" Text="{Binding BusySubscription.ReportPath, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" 
                                  VerticalAlignment="Center" Width="Auto" />

                    </Grid>
                    <Grid x:Name="gridFile" HorizontalAlignment="Stretch"
                           Margin="5,5,5,5" VerticalAlignment="Top" 
                           IsEnabled="{Binding IsEdit}"
                          Visibility="{Binding IsFileSubscription, ConverterParameter=IsFileSubscription, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="1*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Label Content="File Format:" 
                               Grid.Column="0" 
                               Grid.Row="0"
                               VerticalAlignment="Center"
                               HorizontalAlignment="Left"/>
                        <ComboBox 
                            Grid.Column="1" 
                            HorizontalAlignment="Left" 
                            Height="23" 
                            Margin="3" 
                            Grid.Row="0" 
                            Text="{Binding BusySubscription.BusyFileSubscription.Format, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" 
                            VerticalAlignment="Center" 
                            Width="100" >
                            <ComboBoxItem>EXCEL</ComboBoxItem>
                            <ComboBoxItem>CSV</ComboBoxItem>
                            <ComboBoxItem>PDF</ComboBoxItem>
                        </ComboBox>

                        <Label Content="Path:" 
                                   Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="1" VerticalAlignment="Center"/>
                        <TextBox  Grid.Column="1" HorizontalAlignment="Stretch" Height="23" Margin="3" Grid.Row="1" Text="{Binding BusySubscription.BusyFileSubscription.Path, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" 
                                  VerticalAlignment="Center" Width="Auto" />

                    </Grid>

 <!--  DataContext="{Binding BusyMailSubscription, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"-->
                    <Grid x:Name="gridMail" HorizontalAlignment="Stretch"
                          Margin="5,5,5,5" VerticalAlignment="Top"
                       IsEnabled="{Binding IsEdit}"
                         Visibility="{Binding IsMailSubscription, Source={StaticResource viewModel}, ConverterParameter=IsMailSubscription, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                         >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="120"/>
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>

                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Label Content="To:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
                        <TextBox Grid.Column="1" HorizontalAlignment="Stretch"  Height="23" Margin="3" Grid.Row="0" Text="{Binding BusySubscription.BusyMailSubscription.To, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" VerticalAlignment="Center" 
                                 IsReadOnly="{Binding IsReadOnly}"  >
                            

                        </TextBox>
                        <Label Content="Cc:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="1" VerticalAlignment="Center"/>
                        <TextBox  Grid.Column="1" HorizontalAlignment="Stretch" Height="23" Margin="3" Grid.Row="1" Text="{Binding BusySubscription.BusyMailSubscription.Cc, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" />
                        <Label Content="Bcc:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="2" VerticalAlignment="Center"/>
                        <TextBox x:Name="bccTextBox" Grid.Column="1" HorizontalAlignment="Stretch" Height="23" Margin="3" Grid.Row="2" Text="{Binding BusySubscription.BusyMailSubscription.Bcc, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" />

                        <Label Content="From:" Grid.Column="0"  Grid.Row="3"  HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center"/>
                        <TextBox  Grid.Column="1" Grid.Row="3" HorizontalAlignment="Stretch" Height="23" Margin="3"  Text="{Binding BusySubscription.BusyMailSubscription.From, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" />

                        <CheckBox  Grid.Column="1" Grid.Row="4" HorizontalAlignment="Left" Height="23" Margin="3"  IsChecked="{Binding BusySubscription.BusyMailSubscription.IncludeLinkToReport, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Content="Include Link To Report"  />

                        <CheckBox  Grid.Column="1" Grid.Row="5" HorizontalAlignment="Left" Height="23" Margin="3"  IsChecked="{Binding BusySubscription.BusyMailSubscription.ReportAsAttachement, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Content="Include Report As Attachement" />

                        <CheckBox  Grid.Column="1" Grid.Row="6" HorizontalAlignment="Left" Height="23" Margin="3"  IsChecked="{Binding BusySubscription.BusyMailSubscription.ReportInMailBody, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Content="Report in Mail Body" />

                        <Label Content="Attachement Format:" 
                               Grid.Column="0" 
                               Grid.Row="7"
                               VerticalAlignment="Center"
                               HorizontalAlignment="Left"/>
                        <ComboBox 
                            Grid.Column="1" 
                            HorizontalAlignment="Left" 
                            Height="23" 
                            Margin="3" 
                            Grid.Row="7" 
                                 Text="{Binding BusySubscription.BusyMailSubscription.AttachementFormat, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" 
                                 VerticalAlignment="Center" 
                                 Width="100" >
                            <ComboBoxItem>EXCEL</ComboBoxItem>
                            <ComboBoxItem>CSV</ComboBoxItem>
                            <ComboBoxItem>PDF</ComboBoxItem>
                        </ComboBox>
                            <Label Content="Attachement Name:" 
                                   Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="8" VerticalAlignment="Center"/>
                        <TextBox x:Name="attachementNameTextBox" Grid.Column="1" HorizontalAlignment="Stretch" Height="23" Margin="3" Grid.Row="8" Text="{Binding BusySubscription.BusyMailSubscription.AttachementName, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" />


                        <!--To, Cc, Bcc, From, IncludeLinkToReport, ReportAsAttachement, AttachementFormat, AttachementName, ReportInMailBody,  Priority, Subject, Comment-->

                         <Label Content="Priority:" 
                               Grid.Column="0" 
                               Grid.Row="9"
                               VerticalAlignment="Center"
                               HorizontalAlignment="Left"/>
                        
                        <ComboBox 
                            Grid.Column="1" 
                            HorizontalAlignment="Left" 
                            Height="23" 
                            Margin="3" 
                            Grid.Row="9" 
                                 Text="{Binding BusySubscription.BusyMailSubscription.Priority, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" 
                                 VerticalAlignment="Center" 
                                 Width="100" >
                            <ComboBoxItem>Low</ComboBoxItem>
                            <ComboBoxItem>Normal</ComboBoxItem>
                            <ComboBoxItem>High</ComboBoxItem>
                        </ComboBox>

                        <Label Content="Subject:" 
                                   Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="10" VerticalAlignment="Center"/>
                        <TextBox  Grid.Column="1" HorizontalAlignment="Stretch" Height="23" Margin="3" Grid.Row="10" Text="{Binding BusySubscription.BusyMailSubscription.Subject, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center"/>

                        <Label Content="Comment:" 
                                   Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="11" VerticalAlignment="Center"/>
                        <TextBox  Grid.Column="1" HorizontalAlignment="Stretch" Height="69" Margin="3" Grid.Row="11" Text="{Binding BusySubscription.BusyMailSubscription.Comment, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" AcceptsReturn="True"/>

                        
                    </Grid>

                  
                </StackPanel>

                <StackPanel Grid.Column ="1" >
                    <!--  ItemsSource="{Binding ElementName=busySubscriptionDataGrid, Path=SelectedItem.BusySubscriptionsParameters}"-->
                    <DataGrid x:Name="busySubscriptionsParametersDataGrid" AutoGenerateColumns="False" 
                              EnableRowVirtualization="True" Height="200" 
                            CanUserAddRows="False"
                        ItemsSource="{Binding Parameters, UpdateSourceTrigger=PropertyChanged}"
                              Margin="5,5,5,5" 
                              RowDetailsVisibilityMode="VisibleWhenSelected">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding ParameterName}" Header="Name" Width="150"  IsReadOnly="{Binding IsReadOnly,  Source={StaticResource viewModel}}"/>
                            <DataGridTextColumn  Binding="{Binding ParameterValue}" Header="Value" Width="250"  IsReadOnly="{Binding IsReadOnly,  Source={StaticResource viewModel}}"/>
                            <DataGridCheckBoxColumn Binding="{Binding ParameterUseDefault}" Header="Use Default" Width="SizeToHeader"  IsReadOnly="{Binding IsReadOnly,  Source={StaticResource viewModel}}"/>
                        </DataGrid.Columns>
                    </DataGrid>

                    <TextBlock Margin="5,5,5,5" TextWrapping="Wrap"  >Parameter Values are available with the Syntax @ParameterName (Sales_@Month will be replaced with Sales_201412). This works with the Subject, Attachment Name, Comment, File Path fields. Hint: Add (hidden) parameters with default values to your SSRS report to get any string into your filenames, mail subjects, etc.</TextBlock>
                    <TextBlock Margin="5,5,5,5" TextWrapping="Wrap"  ><Run Text="Multivalue Parameters can be set with [value1, value1]. Exclusions ![value1, value2]"/></TextBlock>
                    <TextBlock Margin="5,5,5,5" TextWrapping="Wrap"  ><Run Text="SSAS Parameters need an additional bracket [[dimension].[Hierarchy.[member1], [dimension].[Hierarchy.[member2]]."/></TextBlock>
                    <Button Content="Edit" Margin="5" Click="btnEdit_Click" Width="100" HorizontalAlignment="Left" IsEnabled="{Binding IsReadOnly}"/>
                    <Button x:Name="btnSave" Content="Save" Margin="5" Click="btnSave_Click"  Width="100" HorizontalAlignment="Left" IsEnabled="{Binding IsEdit}"/>
                    <Button Content="Reload Parameters" Margin="5" Click="btnReloadParameters_Click" Width="100" HorizontalAlignment="Left" IsEnabled="{Binding IsEdit}"/>

                </StackPanel>

            </Grid>
        </StackPanel>
    </Grid>
</Window>
